<template>
    <div class="bigBox" v-show="!showDetail">
        <div class="body">
            <Select :types="types" @getData="changeType"></Select>
            <div class="imgsNet">
                <ImgList :imgList="imgList" @viewPicture="viewPicture" :column="1" :loading="loading"></ImgList>
            </div>
        </div>
    </div>
    <Detail v-if="showDetail" @closePicture="closePicture" :urls="imgList" :index="index">
    </Detail>
    <div class="change" @click="getNetImgList" v-show="!showDetail" title="换一批">
        <el-icon>
            <RefreshRight />
        </el-icon>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { get4kWallpaperClassify } from '@renderer/api/mohu'
import { RefreshRight } from '@element-plus/icons-vue'
import ImgList from '@renderer/components/imgList.vue'
import Detail from '@renderer/components/detail.vue'
import _ from 'lodash'
import Select from '@renderer/components/select.vue'
const loading = ref(false)
const types: any = [
    { label: '4K专区', value: '36' },
    { label: '美女模特', value: '6' },
    { label: '爱情美图', value: '30' },
    { label: '风景大片', value: '9' },
    { label: '小清新', value: '15' },
    { label: '动漫卡通', value: '26' },
    { label: '明星风尚', value: '11' },
    { label: '萌宠动物', value: '14' },
    { label: '游戏壁纸', value: '5' },
    { label: '汽车天下', value: '12' },
    { label: '炫酷时尚', value: '10' },
    { label: '月历壁纸', value: '29' },
    { label: '影视剧照', value: '7' },
    { label: '节日美图', value: '13' },
    { label: '军事天地', value: '22' },
    { label: '劲爆体育', value: '16' },
    { label: 'BABY秀', value: '18' },
    { label: '文字控', value: '35' }
]
const page = ref(1)
const size = ref(100)
const type = ref('36')
const imgList: any = ref([])
const index = ref(0)
const showDetail = ref(false)
const changeType = (newType: string) => {
    if (type.value == newType) return
    type.value = newType
    page.value = 1
    imgList.value = []
    getNetImgList()
}
const getNetImgList = async () => {
    imgList.value = []
    loading.value = true
    const obj = {
        count: size.value,
        type: 'json',
        id: type.value
    }
    const res = await get4kWallpaperClassify(obj)
    res.data.forEach((item: any) => {
        imgList.value.push({
            src: item,
            name: res.tag,
            source: item
        })
    })
    loading.value = false
}

const viewPicture = (num: number) => {
    index.value = num
    showDetail.value = true
}
const closePicture = () => {
    showDetail.value = false
}


onMounted(() => {
    getNetImgList()
})
onBeforeUnmount(() => { })
</script>

<style scoped lang="scss">
.bigBox {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;

    .body {
        width: 100%;
        height: 100vh;
        display: grid;
        grid-template-columns: 100px 1fr;


        .imgsNet {
            height: 100vh;
            position: relative;
            @include mixin.scroll_bar();
        }
    }
}

.change {
    width: 32px;
    height: 32px;
    position: fixed;
    right: 10px;
    bottom: 10px;
    background-image: linear-gradient(to right, #0062ff, #33d9b2);
    border-radius: 50%;
    cursor: pointer;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    box-shadow: 0px 0px 10px $primary;

    &:hover {
        animation: rotate 2s linear infinite;
    }
}

// 旋转动画
@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
</style>